package com.mycontract.suitepro.contract

import android.net.Uri

/** 优先级1：从其它app打开 */
object ContractParamsFromApp {

    // 订单号
    var mOrderId: String = ""

    // 产品
    var mProduct: String = ""

    // 手机号
    var mMobile: String = ""

    // 来源
    var mSourceType: String = ""

    // scheme 只有是mSourceType=app时才有值
    var mScheme: String = ""

    // host mSourceType=h5时，它为来源地址
    var mHost: String = ""


    /** 根据外部传参数初始化 */
    fun initSourceData(dataUri: Uri?) {
        dataUri?.let { data ->
            // 订单号
            val orderId: String? = data.getQueryParameter(ContractReviceParams.KEY_ORDER_ID)
            // 手机号
            val mobile: String? = data.getQueryParameter(ContractReviceParams.KEY_MOBILE)
            // 产品
            val product: String? = data.getQueryParameter(ContractReviceParams.KEY_PRODUCT)
            // 来源 app/h5
            val sourceType: String? = data.getQueryParameter(ContractReviceParams.KEY_SOURCE_TYPE)
            // scheme 只有在mSourceType=app时才有值
            val scheme: String? = data.getQueryParameter(ContractReviceParams.KEY_SCHEME)
            // host mSourceType=h5时，它为来源地址
            val host: String? = data.getQueryParameter(ContractReviceParams.KEY_HOST)

            // 保存约定参数
            mMobile = mobile ?: ""
            mOrderId = orderId ?: ""
            mProduct = product ?: ""
            mSourceType = sourceType ?: ""
            mScheme = scheme ?: ""
            mHost = host ?: ""

            // 输出
            printData()
        }
    }

    /** 是否为有效回传值 */
    fun isValidParams(): Boolean {
        return mMobile.isNotBlank()
    }

    /** 输出 */
    fun printData() {
        println("--->orderId:$mOrderId\nmobile:$mMobile\nproduct=$mProduct\nsourceType=$mSourceType\nscheme=$mScheme\nhost=$mHost")
    }
}